package com.sky.context;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * alibaba   TransmittableThreadLocal<Object>
 *           线程变量可以配置后  传递到线程池子线程
 *           自定义线程池      需要使用 TTL 的工具类包装一下
 */
public class AlibabaTTL {
    private AlibabaTTL(){};

    // 线程局部变量 且 线程相互隔离
    private static final TransmittableThreadLocal<Object> context = new TransmittableThreadLocal<Object>();



    //线程保存值
    public static void threadLocalSet(Object obj){
        context.set(obj);
    }

    //线程取值
    public static Object threadLocalGet(){
        return context.get();
    }

    //线程移除值
    public static void threadLocalRemove(){
        context.remove();
    }


}
